<?php

use App\Helpers\DatabaseHelper;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

/**
 * Class CreateDormitoryRatingsTable.
 */
class CreateDormitoryRatingsTable extends Migration
{
	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		Schema::create('dormitory_ratings', function (Blueprint $table) {
			$table->increments('id');
			$table->unsignedInteger('dorm_rating_main_id')->nullable();
			$table->unsignedInteger('company_id')->nullable();
			$table->unsignedInteger('dorm_id');
			$table->unsignedInteger('user_id')->nullable();
			$table->unsignedInteger('period_id')->nullable();
			$table->unsignedInteger('subitem_id');
			$table->float('score')->comment('该宿舍在对应具体项目的得分');
			$table->float('subitem_score')->comment('该宿舍在对应具体项目的满分');
			$table->date('rating_date')->comment('评分日期');
			$table->text('remark')->nullable()->comment('评语');
			$table->timestamps();
			$table->unique(['dorm_id', 'period_id', 'subitem_id']);
		});
		DatabaseHelper::createTriggers('dormitory_ratings', 'dorms');
	}

	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
		Schema::drop('dormitory_ratings');
	}
}
